package 线程.练习;

public class 线程插队 {
    public static void main(String[] args) throws InterruptedException {
        M m = new M();
        Thread thread = new Thread(m);
        for (int i = 0; i < 10; i++) {
            Thread.sleep(1000);
            System.out.println("hi");
            if(i == 4){
                thread.start();
                thread.join();
                System.out.println("子线程结束");
            }
        }
        System.out.println("主线程结束");
    }
}

class M implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
                System.out.println("子线程" + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}